package com.springbootdf.service.impl;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springbootdf.Dto.GameDto;
import com.springbootdf.entity.Game;
import com.springbootdf.entity.JudgeGame;
import com.springbootdf.entity.User;
import com.springbootdf.mapper.GameMapper;
import com.springbootdf.mapper.JudgeGameMapper;
import com.springbootdf.service.GameService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.springbootdf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wy
 * @since 2022-08-18
 */
@Service
public class GameServiceImpl extends ServiceImpl<GameMapper, Game> implements GameService {

    @Resource
    private GameMapper    gameMapper;

    @Resource
    private JudgeGameMapper judgeGameMapper;
    @Override
    public Page<GameDto> findPage(Page<Game> page, String gamename) {
        return gameMapper.findPage(page, gamename);
    }

    @Override
    public void setRoleMenu(Integer gameId, Integer judge) {
        // 先删除当前角色id所有的绑定关系
        //judgeGameMapper.deleteByRoleId(gameId);

        // 再把前端传过来的菜单id数组绑定到当前的这个角色id上去
//        List<Integer> judgeListCopy = CollUtil.newArrayList(judgeList);
//        for (Integer judge : judgeList) {
        List<Integer> judgeListCopy = CollUtil.newArrayList(judge);
        JudgeGame judgeGame = new JudgeGame();
        judgeGame.setGameId(gameId);
        judgeGame.setJudgeId(judge);
        judgeGameMapper.insert(judgeGame);
//        }
    }
}
